package cn.uexpo.lhz.controller.admin;

import cn.uexpo.lhz.common.oldUtils.PageRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.uexpo.lhz.biz.CameranotiyBiz;
import cn.uexpo.lhz.common.oldBase.BaseController;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.core.http.HttpResult;
import cn.uexpo.lhz.domain.Cameranotiy;
import cn.uexpo.lhz.domain.CameranotiyExample;

import java.util.Map;


/**
 *
 * @ClassName:  CameranotifyController
 * @Description:TODO(摄像头：上传数据)
 * @author: 李冬建
 * @date:   2020年6月4日 上午10:25:59
 * @Copyright:  1.0.0
 */
@RestController
@RequestMapping("/cert/notify")
public class CameranotifyController extends BaseController<Cameranotiy>{

	@Autowired
	private CameranotiyBiz cameranotiyBiz;


	/**
	 *
	 * @Title: findPage
	 * @Description: TODO(分页查询)
	 * @param: @param pageRequest
	 * @param: @return
	 * @return: HttpResult
	 * @throws
	 */
	@GetMapping(value="/findPage")//@RequestBody PageRequest pageRequest
	public HttpResult findPage(@RequestParam Map<String, Object> params) {
		PageResult result=findPage1(params);
		return HttpResult.ok(result);
	}


	/**
	 *
	 * @Title: showImgBy
	 * @Description: TODO(查看单个图片)
	 * @param: @param pageRequest
	 * @param: @return
	 * @return: HttpResult
	 * @throws
	 */
	@PostMapping(value="/showImgBy")
	public HttpResult showImgBy(@RequestBody PageRequest pageRequest) {
		int id = Integer.parseInt(pageRequest.getParamValue("id"));//摄像头名称
		Cameranotiy record=cameranotiyBiz.selectByPrimaryKey(id);
		return HttpResult.ok(record);
	}



	private PageResult findPage1(Map<String, Object> params) {
//		Object extstr1 = pageRequest.getParamValue("extstr1");//摄像头名称
//		Object eqpname = pageRequest.getParamValue("eqpname");//设备名称
//		Object address = pageRequest.getParamValue("address");//安装地址

		String page =  (String)params.get("page");
		String limit =  (String)params.get("limit");

		PageRequest request = new PageRequest();
		request.setPage(Integer.parseInt(page));
		request.setLimit(Integer.parseInt(limit));

		String extstr1 = (String)params.get("extstr1");
		String eqpname = (String)params.get("eqpname");
		String address = (String)params.get("address");

		CameranotiyExample example=new CameranotiyExample();
		String orderBy=" createTime ";//默认按照时间降序
	    String sort=" desc ";//默认按照时间降序
		example.setOrderByClause(orderBy+sort);
		CameranotiyExample.Criteria citeria=example.createCriteria();
		if (StringUtils.isNotBlank((String)extstr1)) {
			citeria.andExtstr1Like("%"+(String)extstr1+"%");
		}
		if (StringUtils.isNotBlank((String)eqpname)) {
			citeria.andEqpnameLike("%"+(String)eqpname+"%");
		}
		if (StringUtils.isNotBlank((String)address)) {
			citeria.andAddressLike("%"+(String)address+"%");
		}
		PageResult result=cameranotiyBiz.findPage(request,example);
		return result;
	}





}
